第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Python 在 400 空消息代碼中打印變量輸出

使用 Python 在 400 空消息代碼中打印變量輸出

泛舟湖上清波郎朗 2021-11-30 18:31:16
問題:我正在嘗試為 Discord 編寫一個機器人,以便獲取一個變量并將其作為消息發(fā)送。例如,“a”設(shè)置為 42,我希望機器人在聊天中打印“The number is 42 {author name}”:a = 32if message.content.startswith('!gap'):    msg = print('a'.format(message))    await client.send_message(message.channel, msg)錯誤:Ignoring exception in on_messageTraceback (most recent call last):  File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event    yield from getattr(self, event)(*args, **kwargs)  File "C:\Users\trevo\Desktop\dcbot\reply.py", line 16, in on_message    await client.send_message(message.channel, msg)  File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 1152, in send_message    data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)  File "C:\Users\trevo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\http.py", line 200, in request    raise HTTPException(r, data)discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message我很欣賞解釋!
查看完整描述

2 回答

?
狐的傳說

TA貢獻1804條經(jīng)驗 獲得超3個贊

您希望msg是一個字符串,但如果您嘗試:


>>> msg = print("anything at all")

>>> repr(msg)

None

只需刪除print呼叫。


查看完整回答
反對 回復(fù) 2021-11-30
?
jeck貓

TA貢獻1909條經(jīng)驗 獲得超7個贊

您不應(yīng)該使用 on_message 事件來發(fā)出命令。改用內(nèi)置命令處理程序,這樣可以提高程序設(shè)計和效率。


以下代碼輸出您在!gap后鍵入的數(shù)字


from discord.ext import commands


client = commands.Bot(command_prefix='!')


@client.command(pass_context=True)

async def gap(ctx, number):

    await client.say(f"{ctx.author.mention} said the number {number}")


client.run("token")

我還建議查看 API 的重寫分支,它有很多改進。


查看完整回答
反對 回復(fù) 2021-11-30
  • 2 回答
  • 0 關(guān)注
  • 253 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號