Discord Python Bot 只响应私信消息。

huangapple go评论66阅读模式
英文:

Discord Python Bot only responds to dms

问题

The bot has admin perms, I have no idea why it would do this, seems really weird... any ideas would be great......

This code was generated by ChatGPT btw
Hsggsss hshsssggs
Shsyshgsvsvevsgs
Jshsgscsccsvshshshyw
Hshshsggsfsgs

import discord
import random
from discord.ext import commands

# Define your phrases in a dictionary where the keys are the phrases
# and the values are the corresponding article names
phrases = {
    "Phrase 1": "Article 1",
    "Phrase 2": "Article 2",
    "Phrase 3": "Article 3",
    "Phrase 4": "Article 4"
}

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.command(name='phrase')
async def get_random_phrase(ctx):
    # Get a random phrase from the dictionary
    random_phrase = random.choice(list(phrases.keys()))
    article_name = phrases[random_phrase]

    # Send the random phrase
    message = await ctx.send(f"Here's a random phrase: {random_phrase}")

    def channel_filter(m):
        # Check if the message is correct and from the correct user and in the same server and channel
        return m.author != bot.user and m.guild == ctx.guild and m.channel == ctx.channel and m.content.lower() == article_name.lower()

    try:
        # Wait for a correct message for 30 seconds
        message = await bot.wait_for('message', timeout=30.0, check=channel_filter)

        # If a correct message is received, send a response
        await ctx.send(f"{message.author.mention}, that is correct!")
    except:
        # If no correct message is received, send a timeout message
        await ctx.send("Time's up!")

I tried re inviting the bot to the server, but still won't work.

英文:

The bot has admin perms, I have no idea why it would do this, seems really weird... any ideas would be great......

This code was generated by ChatGPT btw
Hsggsss hshsssggs
Shsyshgsvsvevsgs
Jshsgscsccsvshshshyw
Hshshsggsfsgs

import discord
import random
from discord.ext import commands

# Define your phrases in a dictionary where the keys are the phrases
# and the values are the corresponding article names
phrases = {
    "Phrase 1": "Article 1",
    "Phrase 2": "Article 2",
    "Phrase 3": "Article 3",
    "Phrase 4": "Article 4"
}

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.command(name='phrase')
async def get_random_phrase(ctx):
    # Get a random phrase from the dictionary
    random_phrase = random.choice(list(phrases.keys()))
    article_name = phrases[random_phrase]

    # Send the random phrase
    message = await ctx.send(f"Here's a random phrase: {random_phrase}")

    def channel_filter(m):
        # Check if the message is correct and from the correct user and in the same server and channel
        return m.author != bot.user and m.guild == ctx.guild and m.channel == ctx.channel and m.content.lower() == article_name.lower()

    try:
        # Wait for a correct message for 30 seconds
        message = await bot.wait_for('message', timeout=30.0, check=channel_filter)

        # If a correct message is received, send a response
        await ctx.send(f"{message.author.mention}, that is correct!")
    except:
        # If no correct message is received, send a timeout message
        await ctx.send("Time's up!")

I tried re inviting the bot to the server, but still won't work.

</details>


# 答案1
**得分**: 1

你可能需要使用```message_content```意图。将以下代码添加到你的程序中:
```py
intents.message_content = True

还要前往开发者门户 https://discord.com/developers/applications,然后进入机器人部分并启用message_content

英文:

You probably need the message_content intent.
Add this to your code:

intents.message_content = True

Also go to the Developer Portal https://discord.com/developers/applications and the bot section and enable message_content

huangapple
  • 本文由 发表于 2023年3月4日 02:10:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定