Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

discord.py rewrite - Trying to make a suggestion but channel id gives an error for the command

I've got an issue but I am getting no errors and from the code I just wrote as shown below

@client.commands
async def hello():
    channel = int(797915093954199565)
    await channel.send('Hey what are you doing?')

I am trying to make a command where the user can talk to the bot, and it responds back with something, its just a starting command but I'm having trouble with these small things, the rest of the bot works but its just this issue i'm having please help!

question from:https://stackoverflow.com/questions/65662034/trying-to-make-a-suggestion-but-channel-id-gives-an-error-for-the-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So assuming the rest of your bot and code works, your "hello" command isn't working because you have

@client.commands  #its client.command in this case, as it seems you are not using any cogs, and you must call the client with () these double parentheses 
async def hello():     #Here you have not passed ctx
    channel = int(793744805615632394)   #It seems what you would like to do here is send it to a specific channel, however, in the code below, I have set it so it just sends to the channel it was used in. The correct use is client.get_channel(793744805615632394)
    await channel.send('Hey what are you doing?')

Here is the command but fixed:

So assuming the rest of your bot and code works, your "hello" command isn't working because you have

@client.command()
async def hello(ctx):
    await ctx.send('Hey what are you doing?')

You should also refer to the py docs to learn more about it: https://discordpy.readthedocs.io/en/latest/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...